<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="images/favicon.png">

<link type="text/css" rel="stylesheet" href="${basePath}css/manager/base.css"  />
<link type="text/css" rel="stylesheet" href="${basePath}css/manager/manager_index2.css"  />
<script type="text/javascript" src="${basePath}js/jquery-1.8.3.min.js" ></script>
<script src="${basePath}js/uaredirect.js" type="text/javascript"  ></script>
<script type="text/javascript">  
uaredirect("${basePath}manager/Login_toLogin?mr=mobile");
</script> 
<title>系统后台</title>
</head>
<body style="/*background:#acdce6; */    background: #f1f1f1;" onload="getCookie()">
<div class="login_bg">
  <div class="login_left fl"></div>
  <div class="login_right fr">
    <div class="login_name"><span>登录后台</span></div>
    <div class="account">
      <span>用户名</span>
      <input id="account" class="userName"  type="text" name="userName"  placeholder="请输入用户名"/>
    </div>
    <div class="account">
      <span>密　码</span>
      <input id="account" type="password" class="passWord" name="password"  placeholder="请输入密码"/>
    </div>
    <div class="account">
      <span>验证码</span>
      <input id="account" class="userName" type="text"  name="verifyCode"  placeholder="请输入验证码" style="width: 110px;" />
      <img id="verifyCode" src="${basePath }manager/Login_verifyCode" width="80px" height="32px" style="cursor: pointer;"/>
    </div>
    <div class="clear" style="height:12px; width:300px;"></div>
    <div class="reber_username fl"><input type="checkbox"  id="s1" onClick="check();"/><span>记住用户名</span></div>
    <input type="hidden" id="isRemember" value="">
    <div class="forgot_password fr"><a href="javascript:;"><span></span></a></div>
    <div class="clear" style="height:16px; width:300px;"></div>
    <a href="javascript:login();">
      <div class="login_btn">登录</div>
    </a>
  </div>
</div>
<!--遮罩-->
<div class="login_mask" id="login_mask" style="display:none;">
  <div class="fixed_ts">
    <div class="fixed_box">
      <a href="javascript:;" id="gb_mask">
        <div class="gb_mask" ><img src="${base}/images/manager/gb.png" /></div>
      </a>
      <div class="pic"><img src="${base}/images/manager/zy.png" /></div>
      <div class="fixed_text"><span id="error_message"></span></div>
    </div>
  </div>
</div>
<script type="text/javascript">
$(function(){
	$('#verifyCode').click(function(){
		$('#verifyCode').attr('src','${basePath }manager/Login_verifyCode?m='+Math.random());
	});
	$('.gb_mask').click(function(){
		messageHide();
	});
	$('input').keyup(function(e) {
		if (e.which == 13) {
			login();
		}
	}); 

	
	
});
function check()
{
	var chk = document.getElementById('s1');
	if(chk.checked){
		document.getElementById('isRemember').value=1;
	
	}else{
	    // 不提交
		document.getElementById('isRemember').value=0;
	}
	}
	
	function getCookie(){
		$('input[name=userName]').val("");
		//获取cookie字符串
		var strCookie=document.cookie;
		//将多cookie切割为多个名/值对
		var arrCookie=strCookie.split("; ");
		var userName="";
		//遍历cookie数组，处理每个cookie对
		for(var i=0;i<arrCookie.length;i++){
		var arr=arrCookie[i].split("=");
		//找到名称为userId的cookie，并返回它的值
		if("userName"==arr[0]){
			userName=arr[1];
			$('input[name=userName]').val(userName);
		break;
		}
		} 
	}
	
	function deleteCookie(name){
		//获取当前时间
		var date=new Date();
		//将date设置为过去的时间
		date.setTime(date.getTime()-10000);
		//将userId这个cookie删除
		document.cookie="userName="+name+"; expires="+date.toGMTString(); 
		
	}
function login(){
	var redirectURL=getUrlParam('redirectURL');
	messageHide();
	var userName= $('input[name=userName]').val();
	var passWord= $('.passWord').val();
	var verifyCode =$('input[name=verifyCode]').val();
	var isRemember=$('#isRemember').val();
	if(isRemember==1)
	{
		document.cookie="userName="+userName; 
		var date=new Date();
		var expiresDays=7;
		//将date设置为10天以后的时间
		date.setTime(date.getTime()+expiresDays*24*3600*1000);
		//将userId和userName两个cookie设置为10天后过期
		document.cookie="userName="+userName+"; expires="+date.toGMTString(); 
	}
	if(null == userName || 'undefined'== userName || '' == userName){ 
		messageShow("用户名不能为空");
		return ;
	} 
	if(null == passWord || 'undefined'== passWord || '' == passWord){ 
		messageShow("密码不能为空");
		return ;
	}
	if(null == verifyCode || 'undefined'== verifyCode || '' == verifyCode){ 
		messageShow("验证码不能为空");
		return ;
	}
	
	$.ajax({ 
		url : "${basePath }manager/Login_login",
		data : { 
			userName : userName,
			passWord : passWord,
			verifyCode : verifyCode
		}, 
		dataType :"JSON",
		cache : false, 
		type : "POST",
		success : function(dat){
			if(dat.code==1){
				if(''==redirectURL||null==redirectURL){
					window.location.href="${basePath }manager/Login_index"; 
				}else{
					window.location.href=redirectURL; 
				}
			}else if(dat.code==0){
				messageShow(dat.msg);
			} 	
			$('#verifyCode').attr('src','${basePath }manager/Login_verifyCode?m='+Math.random());
		}
	});
}
	function getUrlParam(name)
	{
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
		var r = window.location.search.substr(1).match(reg);  //匹配目标参数
		if (r!=null) return unescape(r[2]); return null; //返回参数值
	} 
	//显示提示消息
    function messageShow(msg){
		$("#login_mask").show();
		$("#error_message").html(msg);
    }
	//隐藏提示消息
    function messageHide(){
    	$("#login_mask").hide();
		$("#error_message").html();
    }
</script>
</body>
</html>
